package com.mr.base.alpha.sender;

import com.mr.base.alpha.mq.AlphaExchange;
import com.mr.base.alpha.mq.AlphaQueue;
import com.mr.base.alpha.vo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TopicSender {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    //两个消息接受者都可以收到
    public void send_one() {
        Message message = Message.builder()
                .name("测试1")
                .age(1)
                .id(111111111111L)
                .build();
        log.info("Sender : {} " , message);
        this.rabbitTemplate.convertAndSend(AlphaExchange.TOPIC_EXCHANGE, AlphaQueue.TOPIC_ONE,message);
    }


    //只有TopicReceiverTwo都可以收到
    public void send_two() {
        Message message = Message.builder()
                .name("测试2")
                .age(12)
                .id(222222222221L)
                .build();
        log.info("Sender : {} " , message);
        this.rabbitTemplate.convertAndSend(AlphaExchange.TOPIC_EXCHANGE,AlphaQueue.TOPIC_TWO,message);
    }
}
